﻿
Imports System.Data.SqlClient
Imports DTO

Public Class ChucVuDao
    Public Shared Function LayDSDanhSach() As SqlDataAdapter
        Dim dt As New DataTable
        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_laydanhsachchucvu", cn)

        Dim da As New SqlDataAdapter(cmd)
        cn.Close()
        Return da
    End Function

    Public Shared Function LayDanhSach() As DataTable
        Dim dt As New DataTable
        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_laydanhsachchucvu", cn)

        Dim da As New SqlDataAdapter(cmd)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Shared Sub Them(ByVal cv As ChucVuDto)
        Dim cn As SqlConnection = DataProvider.ConnectioData
        cn.Open()
        Dim sql As String = "insert into ChucVu(tencv) values (N'" & cv.TenCV & "')"
        Dim cmd As New SqlCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Shared Sub Xoa(ByVal cv As ChucVuDto)
        Dim cn As SqlConnection = DataProvider.ConnectioData
        cn.Open()
        Dim sql As String = "delete from ChucVu where macv = " & cv.MaCV
        Dim cmd As New SqlCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Shared Sub Sua(ByVal cv As ChucVuDto)
        Dim cn As SqlConnection = DataProvider.ConnectioData
        cn.Open()
        Dim sql As String = "update ChucVu set tencv = N'" & cv.TenCV & "' where macv = " & cv.MaCV
        Dim cmd As New SqlCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub
End Class
